package cn.zhouchao.basic.controller;

import cn.zhouchao.basic.dto.EmailRegisterDto;
import cn.zhouchao.basic.dto.VerifyCodeDto;
import cn.zhouchao.basic.service.IVerifyCodeService;
import cn.zhouchao.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;

/**
 * 后端验证码控制类
 */
@RestController
@RequestMapping("/verifyCode")
public class verifyCodeController {
    /*外部注入的对象*/
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 图形验码的接口
     * @param imageCodeKey
     * @return
     */
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult verifyCode(@PathVariable String imageCodeKey) {//@PathVariable对前端传过来的uuid参数就进行校验了
        String baser64 = verifyCodeService.verifyCode(imageCodeKey);
        return AjaxResult.me().success(baser64);
    }

    /**
     * 手机验证码的接口
     * @param dto
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody VerifyCodeDto dto){
        verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }

    /**
     * 手机号注册接口
     *
     */
    @PostMapping("/phoneRegister")
    public AjaxResult phoneRegister(@RequestBody VerifyCodeDto dto) throws IOException {
        verifyCodeService.phoneRegister(dto);
        return AjaxResult.me().success();

    }

    /**
     * 邮箱验证码的接口
     * @param dto
     * @return
     */
    @PostMapping("/emailCode")
    public AjaxResult emailCode(@RequestBody EmailRegisterDto dto){
        verifyCodeService.emailCode(dto);
        return AjaxResult.me().success();
    }

    /**
     * 邮箱号注册接口
     *
     */
    @PostMapping("/emailRegister")
    public AjaxResult emailRegister(@RequestBody EmailRegisterDto dto) throws IOException {
        verifyCodeService.emailRegister(dto);
        return AjaxResult.me().success();

    }

}
